package com.cskaoyan.catmall.controller.background;

import com.cskaoyan.catmall.model.bo.PageBo;
import com.cskaoyan.catmall.model.pojo.MarketIssue;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.issue.IssueListVo;
import com.cskaoyan.catmall.model.vo.issue.IssueVo;
import com.cskaoyan.catmall.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建日期: 2022/01/07 9:06
 *
 * @author WangZhe
 * 备注:
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    @GetMapping("list")
    public BaseRespVo getListByQuestion(PageBo pageBo, String question) {
        IssueListVo vo = issueService.getListByQuestion(pageBo, question);
        return BaseRespVo.ok(vo);
    }

    @PostMapping("create")
    public BaseRespVo createIssue(@RequestBody MarketIssue marketIssue) {
        IssueVo vo = issueService.createIssue(marketIssue);
        return BaseRespVo.ok(vo);
    }

    @PostMapping("delete")
    public BaseRespVo deleteIssue(@RequestBody MarketIssue marketIssue) {
        issueService.deleteIssue(marketIssue.getId());
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo updateIssue(@RequestBody MarketIssue marketIssue){
        issueService.updateIssue(marketIssue);
        return BaseRespVo.ok(marketIssue);
    }
}
